﻿using DevExpress.Spreadsheet;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using PagedList;
using System.Xml;
using System.IO;
using System.Reflection;

namespace CountTools
{
    public partial class ReportForm : Form
    {
        static AboutDevCompanion devCompanion;
        private List<string> level;
        private Dictionary<string, List<string>> resultsList;
        private string path;

        public ReportForm(List<string> level, Dictionary<string, List<string>> resultsList, string path)
        {
            this.path = path;
            this.level = level;
            this.resultsList = resultsList;
            devCompanion = new AboutDevCompanion(1, false);
            devCompanion.Run();
            InitializeComponent();
            清单构件明细表();
            构件汇总表();
            清单楼层明细表();
            清单汇总表();
            LoadDatas();
        }

        public void LoadDatas()
        {
            int pageSize = 18;
            int totalNum = SetTotalPage(pageSize);

            XmlDocument xml = new XmlDocument();
            xml.Load(path);
            XmlNode mainNode = xml.SelectSingleNode("算量信息");

            #region 设置数据
            IWorkbook workbook = spreadsheetControl_Report.Document;
            Worksheet worksheet = workbook.Worksheets.ActiveWorksheet;
            for (int i = 1; i < totalNum + 1; i++)
            {
                Worksheet worksheetNew = worksheet.Workbook.Worksheets.Add();
                worksheetNew.CopyFrom(worksheet);
                worksheetNew.Name = "清单汇总表_" + i;
                //var pageDatas = _components.OrderBy(a => a.projectCode).GroupBy(a => a.projectCode).ToPagedList(i, pageSize);
                for (int j = 0; j < resultsList.Keys.Count; j++)
                {
                    string codeNum = resultsList.Keys.ElementAt(j);
                    string elementId = resultsList[codeNum][0];

                    XmlNode unitNode = mainNode.SelectSingleNode(elementId).SelectSingleNode("单位");
                    XmlNode textNode = mainNode.SelectSingleNode(elementId).SelectSingleNode("项目特征");
                    XmlNode nameNode = mainNode.SelectSingleNode(elementId).SelectSingleNode("项目名称");
                    string unit = unitNode.InnerText;
                    string text = textNode.InnerText;
                    string name = nameNode.InnerText.Split(' ')[1];

                    double result = 0;

                    for (int k = 0; k < resultsList[codeNum].Count; k++)
                    {
                        string id = resultsList[codeNum][k];
                        XmlNode countNode = mainNode.SelectSingleNode(id).SelectSingleNode("工程量");
                        result += double.Parse(countNode.InnerText);
                    }

                    if (result == 0) continue;

                    worksheetNew.Columns["B"].Skip(6).Take(pageSize).ToArray()[j].SetValue(j + 1); //序号
                    worksheetNew.Columns["C"].Skip(6).Take(pageSize).ToArray()[j].SetValue(codeNum); //项目编码
                    worksheetNew.Columns["D"].Skip(6).Take(pageSize).ToArray()[j].SetValue(name);
                    worksheetNew.Columns["E"].Width = 700;
                    worksheetNew.Columns["E"].Skip(6).Take(pageSize).ToArray()[j].SetValue(text);
                    worksheetNew.Columns["F"].Skip(6).Take(pageSize).ToArray()[j].SetValue(unit);
                    worksheetNew.Columns["G"].Skip(6).Take(pageSize).ToArray()[j].SetValue(result.ToString("0.00"));
                    worksheetNew.Columns["E"].Alignment.WrapText = true;
                    worksheetNew.Columns["E"].Alignment.Horizontal = SpreadsheetHorizontalAlignment.Left;
                }
                worksheetNew.Cells.Alignment.WrapText = true;
                worksheetNew.ActiveView.Zoom = 100;//单元格显示的大小

            }

            if (workbook.Worksheets.Count > 1)
            {
                workbook.Worksheets.RemoveAt(0);

            }
            if (workbook.Worksheets.Count > 2)
            {
                barButtonItem_nextPage.Enabled = true;
            }

            workbook.Worksheets.ActiveWorksheet = workbook.Worksheets[0];
            string dllPath = Path.GetDirectoryName(path) +"\\Temp";
            string xmlPath = Path.Combine(dllPath, "清单汇总表");
            workbook.SaveDocument(xmlPath, DocumentFormat.Xlsx);
            #endregion
        }
        /// <summary>
        /// 电子表格模板
        /// </summary>
        /// <param name="worksheetName">工作表名称</param>
        /// <param name="tableTitle">表标题</param>
        /// <param name="headers">表头</param>
        /// <param name="projectName">项目名称</param>
        public Worksheet InitSpreadsheetControl(string worksheetName, string tableTitle, string projectName, Dictionary<string, string> headers)
        {
            //页面设置   
            spreadsheetControl_Report.CreateNewDocument();
            IWorkbook workbook = spreadsheetControl_Report.Document;
            workbook.CreateNewDocument();
            workbook.Worksheets[0].ActiveView.PaperKind = System.Drawing.Printing.PaperKind.A3; //设置纸张大小
            WorksheetCollection worksheets = workbook.Worksheets;
            Worksheet worksheet = workbook.Worksheets[0];
            worksheet.Name = worksheetName;
            worksheet.Cells.Borders.SetAllBorders(Color.White, BorderLineStyle.Dotted);
            worksheet.Cells.Alignment.Vertical = SpreadsheetVerticalAlignment.Center;//垂直居中
            worksheet.Cells.Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center;//水平居中
            worksheet.Cells.Alignment.WrapText = true;

            //设置单元格的宽度
            worksheet.Columns["B"].Width = 330;
            worksheet.Columns["C"].Width = 430;
            worksheet.Columns["D"].Width = 550;
            worksheet.Columns["E"].Width = 700;
            worksheet.Columns["F"].Width = 340;
            worksheet.Columns["G"].Width = 340;

            //设置标题
            Range title = worksheet["B2:G2"];
            worksheet.MergeCells(title);//合并单元格
            title.Value = tableTitle;
            title.Borders.SetAllBorders(Color.White, BorderLineStyle.Dotted);
            title.Font.Size = 20;
            title.RowHeight = 200;
            title.Font.FontStyle = SpreadsheetFontStyle.Regular;
            title.Alignment.Vertical = SpreadsheetVerticalAlignment.Center;
            title.Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center;

            //设置项目名称
            Range project = worksheet["B4:D4"];
            worksheet.MergeCells(project);
            project.Value = projectName;
            project.Alignment.Vertical = SpreadsheetVerticalAlignment.Center;
            project.Alignment.Horizontal = SpreadsheetHorizontalAlignment.Left;
            project.RowHeight = 100;

            //设置日期
            Range CreateTime = worksheet["F4:G4"];
            worksheet.MergeCells(CreateTime);
            CreateTime.Value = "编制日期：" + DateTime.Now.ToString("yyyy-MM-dd");
            CreateTime.Alignment.Vertical = SpreadsheetVerticalAlignment.Center;
            CreateTime.Alignment.Horizontal = SpreadsheetHorizontalAlignment.Right;
            CreateTime.RowHeight = 100;

            //设置表头
            foreach (var header in headers)
            {
                worksheet.Range[header.Key].SetValue(header.Value);
                worksheet.Range[header.Key].RowHeight = 100;
                worksheet.Range[header.Key].Font.FontStyle = SpreadsheetFontStyle.Bold;
            }

            return worksheet;
        }


        public void 清单汇总表()
        {
            Dictionary<string, string> headers = new Dictionary<string, string>();
            headers.Add("B5", "序号");
            headers.Add("C5", "项目编码");
            headers.Add("D5", "项目名称");
            headers.Add("E5", "项目特征");
            headers.Add("F5", "计量单位");
            headers.Add("G5", "工程量");
            string worksheetName = "清单汇总表";
            string tableTitle = "清单汇总表";
            string projectName = "项目工程名称：";

            Worksheet worksheet = InitSpreadsheetControl(worksheetName, tableTitle, projectName, headers);
            IWorkbook workbook = worksheet.Workbook;

            //画表格的线,设置更改表格的格式
            Range B5toF40 = worksheet["B5:G24"];
            B5toF40.Borders.SetAllBorders(Color.Black, BorderLineStyle.Thin);//单元格边框SetAllBorders所有边框
            B5toF40.Borders.SetOutsideBorders(Color.Black, BorderLineStyle.Medium);//SetOutsideBorders外框
            B5toF40.Alignment.Vertical = SpreadsheetVerticalAlignment.Center;//垂直居中
            B5toF40.Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center;//水平居中

            Range projectType = worksheet["B6:E6"];
            worksheet.MergeCells(projectType);
            projectType.Value = "混凝土及钢筋混凝土工程";
            projectType.Alignment.Vertical = SpreadsheetVerticalAlignment.Center;
            projectType.Alignment.Horizontal = SpreadsheetHorizontalAlignment.Left;
            projectType.RowHeight = 100;
            projectType.Font.FontStyle = SpreadsheetFontStyle.Bold;
            workbook.Worksheets.ActiveWorksheet = workbook.Worksheets[0];
            string dllPath = Path.GetDirectoryName(path) + "\\Temp";
            string xmlPath = Path.Combine(dllPath, "清单汇总表模板");
            workbook.SaveDocument(xmlPath, DocumentFormat.Xlsx);
        }

        public void 清单楼层明细表()
        {
            Dictionary<string, string> headers = new Dictionary<string, string>();
            headers.Add("B5", "序号");
            headers.Add("C5", "项目编码");
            headers.Add("D5", "项目名称/楼层名称");
            headers.Add("E5", "项目特征");
            headers.Add("F5", "计量单位");
            headers.Add("G5", "工程量");

            string worksheetName = "清单楼层明细表";
            string tableTitle = "清单楼层明细表";
            string projectName = "项目工程名称：";

            Worksheet worksheet = InitSpreadsheetControl(worksheetName, tableTitle, projectName, headers);
            IWorkbook workbook = worksheet.Workbook;

            Range B5toF40 = worksheet["B5:G41"];
            B5toF40.Borders.SetAllBorders(Color.Black, BorderLineStyle.Thin);//单元格边框SetAllBorders所有边框
            B5toF40.Borders.SetOutsideBorders(Color.Black, BorderLineStyle.Medium);//SetOutsideBorders外框
            B5toF40.Alignment.Vertical = SpreadsheetVerticalAlignment.Center;//垂直居中
            B5toF40.Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center;//水平居中

            Range rangeB6toB13 = worksheet["B6:B13"];
            worksheet.MergeCells(rangeB6toB13);
            rangeB6toB13.SetValue("1");

            Range rangeC7toC13 = worksheet["C7:C13"];
            worksheet.MergeCells(rangeC7toC13);

            Range rangeD13toE13 = worksheet["D13:E13"];
            worksheet.MergeCells(rangeD13toE13);
            rangeD13toE13.SetValue("小计");

            worksheet.Cells["C6"].SetValue("01054678978");
            worksheet.Cells["D6"].SetValue("圈梁");
            worksheet.Cells["E6"].SetValue(" 1.混凝土类型：混凝土\n 2.混凝土搅拌制作：预拌商品硂\n 3.混凝土强度等级：c10");
            worksheet.Cells["E6"].Alignment.Horizontal = SpreadsheetHorizontalAlignment.Left;//水平居中

            if (workbook.Worksheets.Count > 1)
            {
                workbook.Worksheets.RemoveAt(0);
            }

            workbook.Worksheets.ActiveWorksheet = workbook.Worksheets[0];
            string dllPath = Path.GetDirectoryName(path) + "\\Temp";
            string xmlPath = Path.Combine(dllPath, "清单楼层明细表");
            workbook.SaveDocument(xmlPath, DocumentFormat.Xlsx);

        }

        public void 构件汇总表()
        {
            Dictionary<string, string> headers = new Dictionary<string, string>();
            headers.Add("B5", "序号");
            headers.Add("C5", "构件名称/项目编码");
            headers.Add("D5", "项目名称");
            headers.Add("E5", "项目特征");
            headers.Add("F5", "计量单位");
            headers.Add("G5", "工程量");

            string worksheetName = "构件汇总表";
            string tableTitle = "构件汇总表";
            string projectName = "项目工程名称：";

            Worksheet worksheet = InitSpreadsheetControl(worksheetName, tableTitle, projectName, headers);
            IWorkbook workbook = worksheet.Workbook;

            Range B5toF40 = worksheet["B5:G41"];
            B5toF40.Borders.SetAllBorders(Color.Black, BorderLineStyle.Thin);//单元格边框SetAllBorders所有边框
            B5toF40.Borders.SetOutsideBorders(Color.Black, BorderLineStyle.Medium);//SetOutsideBorders外框
            B5toF40.Alignment.Vertical = SpreadsheetVerticalAlignment.Center;//垂直居中
            B5toF40.Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center;//水平居中

            Range rangeB6toG6 = worksheet["B6:G6"];
            worksheet.MergeCells(rangeB6toG6);
            rangeB6toG6.RowHeight = 200;
            rangeB6toG6.FillColor = Color.Gray;

            Range rangeB7toG7 = worksheet["B7:G7"];
            worksheet.MergeCells(rangeB7toG7);
            rangeB7toG7.RowHeight = 100;

            Range rangeB8toB10 = worksheet["B8:B10"];
            worksheet.MergeCells(rangeB8toB10);
            rangeB8toB10.SetValue("1");

            Range rangeC8toG10 = worksheet["C8:G8"];
            worksheet.MergeCells(rangeC8toG10);
            rangeC8toG10.SetValue("XX板");
            rangeC8toG10.Alignment.Horizontal = SpreadsheetHorizontalAlignment.Left;

            if (workbook.Worksheets.Count > 2)
            {
                barButtonItem_nextPage.Enabled = true;
            }

            if (workbook.Worksheets.Count > 1)
            {
                workbook.Worksheets.RemoveAt(0);
            }

            workbook.Worksheets.ActiveWorksheet = workbook.Worksheets[0];
            string dllPath = Path.GetDirectoryName(path) + "\\Temp";
            string xmlPath = Path.Combine(dllPath, "构件汇总表");
            workbook.SaveDocument(xmlPath, DocumentFormat.Xlsx);
        }
        public void 清单构件明细表()
        {
            Dictionary<string, string> headers = new Dictionary<string, string>();
            headers.Add("B5", "序号");
            headers.Add("C5", "项目编码/楼层");
            headers.Add("D5", "项目名称/构件名称");
            headers.Add("E5", "项目特征");
            headers.Add("F5", "计量单位");
            headers.Add("G5", "工程量");

            string worksheetName = "清单构件明细表";
            string tableTitle = "清单构件明细表";
            string projectName = "项目工程名称：";

            Worksheet worksheet = InitSpreadsheetControl(worksheetName, tableTitle, projectName, headers);
            IWorkbook workbook = worksheet.Workbook;

            //画表格的线
            Range B5toF40 = worksheet["B5:G41"];
            B5toF40.Borders.SetAllBorders(Color.Black, BorderLineStyle.Thin);//单元格边框SetAllBorders所有边框
            B5toF40.Borders.SetOutsideBorders(Color.Black, BorderLineStyle.Medium);//SetOutsideBorders外框
            B5toF40.Alignment.Vertical = SpreadsheetVerticalAlignment.Center;//垂直居中
            B5toF40.Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center;//水平居中

            for (int i = 6; i <= 6; i = i + 4)
            {
                string reference = "B" + i + ":B" + (i + 3);
                Range rangeNumtest = worksheet[reference];
                worksheet.MergeCells(rangeNumtest);
                rangeNumtest.Value = "1";
                rangeNumtest.Alignment.Vertical = SpreadsheetVerticalAlignment.Center;
                rangeNumtest.Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center;
                rangeNumtest.RowHeight = 100;

                worksheet.MergeCells(worksheet["C" + (i + 1) + ":C" + (i + 2)]);
                worksheet.MergeCells(worksheet["D" + (i + 1) + ":E" + (i + 1)]);

                Range subtotal = worksheet["D" + (i + 2) + ":E" + (i + 2)];
                subtotal.Value = "小计";
                subtotal.Alignment.Vertical = SpreadsheetVerticalAlignment.Center;
                subtotal.Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center;
                subtotal.RowHeight = 100;
                worksheet.MergeCells(subtotal);

                Range total = worksheet["D" + (i + 3) + ":E" + (i + 3)];
                total.Value = "合计";
                total.Alignment.Vertical = SpreadsheetVerticalAlignment.Center;
                total.Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center;
                total.RowHeight = 100;
                worksheet.MergeCells(total);
                total.FillColor = Color.Gray;
                Range rangeFG = worksheet["F" + (i + 3) + ":G" + (i + 3)];
                rangeFG.FillColor = Color.Gray;
            }
            #region 设置数据
            //int pageSize = 9;
            //int totalNum = SetTotalPage(pageSize);
            //for (int pageNum = 1; pageNum < totalNum + 1; pageNum++)
            //{
            //    int dataNum = 0;
            //    Worksheet worksheetNew = workbook.Worksheets.Add();
            //    worksheetNew.CopyFrom(worksheet);
            //    worksheetNew.Name = "清单构件明细表_" + pageNum;
            //    var pageDatas = _components.OrderBy(a => a.projectCode).GroupBy(a => a.projectCode).ToPagedList(pageNum, pageSize);
            //    for (int i = 6; i <= 41 && dataNum < pageDatas.Count; i = i + 4, dataNum++)
            //    {
            //        worksheetNew.Cells["C" + i].SetValue(pageDatas[dataNum].First().projectCode);
            //        worksheetNew.Cells["D" + i].SetValue(" 国家了国家爱离开过阿里股价啦干阿里股价昂科拉过啦啦格拉国家啦孤狼狼狼了国家了国家阿里嘎拉国家了巨浪狼藉阿里股价啦干捡垃圾阿里股价啦个拉几个啦个垃圾狗垃圾狗狼了 ");
            //        worksheetNew.Cells["D" + i].Alignment.WrapText = true;
            //        worksheetNew.Cells["F" + i].SetValue("立方米");
            //        worksheetNew.Cells["G" + i].SetValue(pageDatas[dataNum].Sum(a => a.projectBudget).ToString("0.00"));
            //        worksheetNew.Cells["D" + i].AutoFitRows();
            //        worksheetNew.Cells["D" + i].Alignment.Horizontal = SpreadsheetHorizontalAlignment.Left;
            //    }
            //    worksheetNew.Cells.Alignment.WrapText = true;
            //    //worksheetNew.FreezePanes(100, 10);
            //    worksheetNew.ActiveView.Zoom = 100;//单元格显示的大小
            //}
            #endregion 
            if (workbook.Worksheets.Count > 2)
            {
                barButtonItem_nextPage.Enabled = true;
            }

            if (workbook.Worksheets.Count > 1)
            {
                workbook.Worksheets.RemoveAt(0);
            }

            workbook.Worksheets.ActiveWorksheet = workbook.Worksheets[0];
            string dllPath = Path.GetDirectoryName(path) + "\\Temp";
            string xmlPath = Path.Combine(dllPath, "清单构件明细表");
            workbook.SaveDocument(xmlPath, DocumentFormat.Xlsx);
        }

        public int SetTotalPage(int pageSize)
        {
            int totalNum = 0;

            int dataCount = resultsList.Keys.Count;
            if (dataCount % pageSize == 0)
            {
                totalNum = dataCount / pageSize;
            }
            else
            {
                totalNum = dataCount / pageSize + 1;
            }
            barTotalPage.Caption = "共（" + totalNum + "）页";

            return totalNum;
        }




        private void navBarItem1_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            string dllPath = Path.GetDirectoryName(path) + "\\Temp";
            string xmlPath = Path.Combine(dllPath, "清单汇总表");
            LinkClick(xmlPath);
        }

        private void navBarItem2_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            string dllPath = Path.GetDirectoryName(path) + "\\Temp";
            string xmlPath = Path.Combine(dllPath, "构件汇总表");
            LinkClick(xmlPath);
        }

        private void navBarItem3_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            string dllPath = Path.GetDirectoryName(path) + "\\Temp";
            string xmlPath = Path.Combine(dllPath, "清单楼层明细表");
            LinkClick(xmlPath);
        }

        private void navBarItem4_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            string dllPath = Path.GetDirectoryName(path) + "\\Temp";
            string xmlPath = Path.Combine(dllPath, "清单构件明细表");
            LinkClick(xmlPath);
        }

        public void LinkClick(string fileName)
        {
            IWorkbook workbook = spreadsheetControl_Report.Document;
            try
            {
                workbook.LoadDocument(fileName, DocumentFormat.Xlsx);
                workbook.Worksheets.ActiveWorksheet = workbook.Worksheets[0];
                spreadsheetBarController_Report.Control.Focus();
                workbook.Worksheets[0].ScrollToRow(0);
            }
            catch (Exception ex)
            {
                MessageBox.Show("加载失败！" + ex.Message);
                return;
            }

            barEditItemInputPageNum.EditValue = 1;
            int workSheetCount = workbook.Worksheets.Count;

            if (workSheetCount <= 1)
            {
                barButtonPrePage.Enabled = false;
                barButtonItem_nextPage.Enabled = false;
            }
            else
            {
                barButtonPrePage.Enabled = false;
                barButtonItem_nextPage.Enabled = true;
            }

            barTotalPage.Caption = "共（" + workbook.Worksheets.Count + "）页";
        }

        private void barButtonPrePage_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            IWorkbook workbook = spreadsheetControl_Report.Document;
            Worksheet worksheet = workbook.Worksheets.ActiveWorksheet;
            int index = worksheet.Index;//namenum值0开始（0时表示第一个工作表，1表示第二个工作表......）
            workbook.Worksheets.ActiveWorksheet = workbook.Worksheets[index - 1];//显示当前工作文档位置
            barEditItemInputPageNum.EditValue = index;//显示当前页码
            barButtonItem_nextPage.Enabled = true;//下一页按钮是否可用
            if (index < 2)
            {
                barButtonPrePage.Enabled = false;//上一页按钮是否可用
            }
        }

        private void barButtonItem_nextPage_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            IWorkbook workbook = spreadsheetControl_Report.Document;
            Worksheet viewworksheet = workbook.Worksheets.ActiveWorksheet;
            int index = viewworksheet.Index;
            workbook.Worksheets.ActiveWorksheet = workbook.Worksheets[index + 1];
            index += 2;
            barEditItemInputPageNum.EditValue = index;//显示页码
            barButtonPrePage.Enabled = true;
            if (index >= workbook.Worksheets.Count)
                barButtonItem_nextPage.Enabled = false;
            else
                barButtonItem_nextPage.Enabled = true;
        }

        private void barEditItemInputPageNum_EditValueChanged(object sender, EventArgs e)
        {
            int editValue = 0;
            IWorkbook workbook = spreadsheetControl_Report.Document;
            Worksheet viewworksheet = workbook.Worksheets.ActiveWorksheet;
            if (int.TryParse(barEditItemInputPageNum.EditValue.ToString(), out editValue))
            {
                if (editValue <= 0 || editValue > workbook.Worksheets.Count)
                {
                    MessageBox.Show("输入的页数范围不对！");
                    return;
                }
                else if (editValue == 1)
                {
                    barButtonPrePage.Enabled = false;
                    if (workbook.Worksheets.Count > 1)
                    {
                        barButtonItem_nextPage.Enabled = true;
                    }
                    else
                    {
                        barButtonItem_nextPage.Enabled = false;
                    }
                }
                else if (editValue == workbook.Worksheets.Count)
                {
                    barButtonItem_nextPage.Enabled = false;
                    barButtonPrePage.Enabled = true;
                }
                workbook.Worksheets.ActiveWorksheet = workbook.Worksheets[editValue - 1];
            }
            else
            {
                MessageBox.Show("输入的页数格式不对！");
            }
        }

        private void barButtonItem_FirstPage_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            barEditItemInputPageNum.EditValue = 1;
            IWorkbook workbook = spreadsheetControl_Report.Document;
            workbook.Worksheets.ActiveWorksheet = workbook.Worksheets[0];
        }

        private void barButtonItem_LastPape_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            IWorkbook workbook = spreadsheetControl_Report.Document;
            workbook.Worksheets.ActiveWorksheet = workbook.Worksheets[workbook.Worksheets.Count - 1];
            barEditItemInputPageNum.EditValue = workbook.Worksheets.Count;
        }
    }
}
